package org.diysearch.services;

import javax.servlet.http.HttpSession;

import org.diysearch.interfaces.Product;
import org.diysearch.models.Status;
import org.diysearch.products.JsonProduct;

public class Logout extends BaseService {
	private String uri;
	
	@Override
	public Product execute() throws Exception {
		Product p = new JsonProduct();
		Status s = new Status();
		p.setWriter(writer);
		
		HttpSession session = request.getSession();
		
		try {
			session.removeAttribute("user");
			session.invalidate();
			s.setCode(1);
			s.setMessage("logged out");
		} catch (Exception ex) {
			s.setCode(-1);
			s.setMessage("couldn't log out. weird");
		}
		p.setOutput(s);
		return p;
	}

	@Override
	public boolean isWriter() {
		return true;
	}

	@Override
	public String getUri() {
		return uri;
	}

	@Override
	public void setUri(String uri) {
		this.uri = uri;
	}

}
